package com.m1905hd.user.web.controller

import com.m1905hd.user.entity.User
import com.m1905hd.user.model.BuiMenu
import com.m1905hd.user.service.ResourceService
import com.m1905hd.user.service.UserService
import com.m1905hd.user.web.bind.annotation.CurrentUser
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.RequestMapping

/**
 *
 * @author weiwei.huang
 * @email ihuangweiwei@163.com
 * @date 15/3/31
 */
@Controller
class IndexController {


    @Autowired
    UserService userService


    @Autowired
    ResourceService resourceService

    @RequestMapping("/")
    public String index(@CurrentUser User loginUser, Model model) {
        Set<String> permissions = this.userService.findPermissions(loginUser.getUserName())
        BuiMenu buiMenu = this.resourceService.getBuiMenuConfig(permissions)
        model.addAttribute("navList", buiMenu.titles)
        model.addAttribute("realName", loginUser.realName)
        model.addAttribute("config", buiMenu.config)
        return "index";
    }

}
